package com.knoya.chejian.pda.myadapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.knoya.chejian.pda.R
import com.knoya.chejian.pda.activity.MainActivity
import com.knoya.chejian.pda.minterface.MainButtonInterface
import kotlinx.android.synthetic.main.item_mian_button.view.*

class MainButtonAdapter(private var mlist: List<String>, private val mcontext: Context, val inter : MainButtonInterface) : BaseAdapter() {
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v :View
        var h : Header
        if(convertView==null){
            v=minflater.inflate(R.layout.item_mian_button,null)
            h= Header(v)
            v.tag=h
        }else{
            v=convertView
            h=v.tag as Header
        }
        h.Bu_Main.text = mlist[position]
        h.Bu_Main.setOnClickListener {
            inter.onbutton(mlist[position])
        }
        return v
    }

    override fun getItem(position: Int): Any {
        return mlist[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return mlist.size
    }
    class Header(var v : View){
        val Bu_Main=v.Bu_Main
    }
}